package com.lytfly.flowable.modules.flow.service.impl;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.StrUtil;
import com.lytfly.flowable.domain.CommentTypeEnum;
import com.lytfly.flowable.modules.flow.entity.FlowCommentInfo;
import com.lytfly.flowable.modules.flow.mapper.FlowCommentInfoMapper;
import com.lytfly.flowable.modules.flow.service.IFlowCommentInfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author liuyuantao
 * @since 2021年07月15日 13时40分
 */
@Service
public class FlowCommentInfoServiceImpl extends ServiceImpl<FlowCommentInfoMapper, FlowCommentInfo> implements IFlowCommentInfoService {
    /**
     * 保存审批意见
     *
     * @param commentInfo 实体
     */
    @Override
    public void saveComment(FlowCommentInfo commentInfo) {
        commentInfo.insert();
    }

    /**
     * 通过流程实例id获取审批意见列表
     *
     * @param processInstanceId 流程实例id
     * @return
     */
    @Override
    public List<FlowCommentInfo> getCommentInfosByProcessInstanceId(String processInstanceId) {
        List<FlowCommentInfo> commentInfoList = baseMapper.getCommentInfosByProcessInstanceId(processInstanceId);
        if (CollUtil.isNotEmpty(commentInfoList)) {
            commentInfoList.forEach(commentInfo -> {
                if (StrUtil.isNotBlank(commentInfo.getType())) {
                    commentInfo.setTypeName(CommentTypeEnum.getEnumMsgByType(commentInfo.getType()));
                }
            });
        }
        return commentInfoList;
    }
}
